<?php
/**
 *description:出库
 *author:李飞
 *time:2016/12/29
 */

namespace Agent\Controller;
use Think\Controller;
class OutboundController extends BaseController {
	
	public function _initialize()
    {
        parent::_initialize();
        $g=session('agent');
		C('erp_dbname',$g['db']);
        $db_name=$g['db'];
		//数据库连接基础配置-begin
		C('db_config.DB_TYPE',C('DB_TYPE'));
		C('db_config.DB_HOST',C('DB_HOST'));
		C('db_config.DB_USER',C('DB_USER'));
		C('db_config.DB_PWD',C('DB_PWD'));
		C('db_config.DB_PORT',C('DB_PORT'));
		C('db_config.DB_CHARSET',C('DB_CHARSET'));
		C('db_config.DB_NAME',C('erp_dbname'));
		//数据库连接基础配置-end
    }
	
    public function index(){
		$this->redirect('pushorder');
    }

	public function printorder_picklist(){
		$this->display();
    }
	public function own_delivery(){
		$this->display();
    }

	public function get_picklist_printorder(){
		$m=M('Picklist',C('DB_PRS'),C('DB_DEPOT'));
		$n=M('Pickorder',C('DB_PRS'),C('DB_DEPOT'));
		$p=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));

		$id=I('picklist_id');
		$picklist_info=$m->where(array('id'=>$id))->find();
		// echo $m->getlastsql();
		$pickorder_list=$n->where(array('picklist_no'=>$picklist_info['picklist_no']))->select();
		// echo $n->getlastsql();
		// dump($pickorder_list);
		$arr=array();
		foreach($pickorder_list as $k=>$v){
			$arr[]=$v['order_id'];
		}
		// dump($arr);
		$info=$p->where(array('id'=>array('in',$arr)))->select();
		// dump($info);
		// echo $p->getlastsql();
		foreach($info as $ks=>$vs){
			$info[$ks]['add_time']=date("Y-m-d",$vs['add_time']);
		}
		if(!empty($info)){
            $data['total']=count($info);
            $data['rows']=$info;
        }else{
            $data['total']=0;
            $data['rows']=0;
        }
		
        $this->ajaxReturn($data);
	}
	//获取面单列表数据(一般订单)
	public function printorder(){
		$m=M('Pushorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$n=M('Pushordergoods', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$model=M('', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		
        //搜索条件
        $map=array();
		// $map['pick_status']=0;//未生成波次单
		//拦截
		$inter_list=$this->zintercepted();//拦截订单列表
		$cc=count($inter_list);//拦截订单数量
		if($cc){ //cc大于0，则说明有拦截订单
			foreach($inter_list as $key=>$val){
				$arr[$key]=$val['order_no'];
			}
			$map['order_no']=array('not in',$arr); //移除拦截订单
		}
		$order_no=I('order_no','',trim);
		$mailNo=I('mailNo','',trim);
		$receiveMan=I('receiveMan','',trim);
		$print_status=I('print_status','',trim);
		$start_time=I('start_time','',trim);
		$end_time=I('end_time','',trim);
		$ems_code=I('ems_code','',trim);
		
        $goods_name=I('goods_name','',trim);
		$number=I('nums','',trim);
		$radio_pick=I('check_cate');
		
		$map['order_cate']=1;
		!empty($order_no)?$map['order_no']=array('like','%'.$order_no.'%'):'';
        !empty($mailNo)?$map['logistics_no']=array('like','%'.$mailNo.'%'):'';
		!empty($receiveMan)?$map['user_name']=array('like','%'.$receiveMan.'%'):'';
		!empty($start_time)?$start_time = strtotime($start_time):$start_time=0;
		!empty($end_time)?$end_time = strtotime($end_time):$end_time =time();
		!empty($ems_code)?$map['logistics_business']=$ems_code:'';
		$map['_string'] = "add_time>=$start_time AND add_time<=$end_time";
		
		if($print_status==1){
			$map['times']=0;
		}
		if($print_status==2){
			$map['times']=array('GT',0);
		}
		
		$p=I('p')?I('p'):1;
		$listrows=20;
		$firstrow=($p-1)*$listrows;
        
		if($radio_pick==1){ //完全匹配（唯一）
			if($number==''){
				$error_text="数量不能为空";
				$this->error($error_text);
			}
			$map['goods_nums']=$number;
			//生成子查询sql语句
			$sql=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('g.order_id,g.goods_nums,g.goods_name,o.province,o.city,o.area,o.id,o.order_no,o.logistics_no,o.times,o.add_time,o.user_idcard,o.user_name,o.user_phone,o.user_address')->where($map)->buildSql();
			$list_count=$model->table($sql.' a')->group('order_id')->having("count(order_id)=1 and goods_name='$goods_name'")->select();
			$count=count($list_count);
			$info=$model->table($sql.' a')->group('order_id')->having("count(order_id)=1 and goods_name='$goods_name'")->limit($firstrow.','.$listrows)->order('id desc')->select();
			
		}
		if($radio_pick==5){ //商品唯一但不匹配此商品数量
			if($number==''){
				$error_text="数量不能为空";
				$this->error($error_text);
			}
			$map['goods_nums']=array('neq',$number);
			//生成子查询sql语句
			$sql=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('g.order_id,g.goods_nums,g.goods_name,o.province,o.city,o.area,o.id,o.order_no,o.logistics_no,o.times,o.add_time,o.user_idcard,o.user_name,o.user_phone,o.user_address')->where($map)->buildSql();
			$list_count=$model->table($sql.' a')->group('order_id')->having("count(order_id)=1 and goods_name='$goods_name'")->select();
			$count=count($list_count);
			$info=$model->table($sql.' a')->group('order_id')->having("count(order_id)=1 and goods_name='$goods_name'")->limit($firstrow.','.$listrows)->order('id desc')->select();
		}

		if($radio_pick==2){ //包含此商品并且匹配此商品数量
			if($number==''){
				$error_text="数量不能为空";
				$this->error($error_text);
			}
			$map['goods_nums']=$number;
			//生成子查询sql语句
			$sql=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('g.order_id,g.goods_nums,g.goods_name,o.province,o.city,o.area,o.id,o.order_no,o.logistics_no,o.times,o.add_time,o.user_idcard,o.user_name,o.user_phone,o.user_address')->where($map)->buildSql();
			$list_count=$model->table($sql.' a')->group('order_id')->having("count(order_id)<>1 and goods_name='$goods_name'")->select();
			$count=count($list_count);
			$info=$model->table($sql.' a')->group('order_id')->having("count(order_id)<>1 and goods_name='$goods_name'")->limit($firstrow.','.$listrows)->order('id desc')->select();
			// echo $model->getlastsql();
			// die;
		}
		if($radio_pick==3){ //包含此商品但不匹配此商品数量
			if($number==''){
				$error_text="数量不能为空";
				$this->error($error_text);
			}
			$map['goods_nums']=array('neq',$number);
			//生成子查询sql语句
			$sql=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('g.order_id,g.goods_nums,g.goods_name,o.province,o.city,o.area,o.id,o.order_no,o.logistics_no,o.times,o.add_time,o.user_idcard,o.user_name,o.user_phone,o.user_address')->where($map)->buildSql();
			$list_count=$model->table($sql.' a')->group('order_id')->having("count(order_id)<>1 and goods_name='$goods_name'")->select();
			$count=count($list_count);
			$info=$model->table($sql.' a')->group('order_id')->having("count(order_id)<>1 and goods_name='$goods_name'")->limit($firstrow.','.$listrows)->order('id desc')->select();
		}
		if($radio_pick==4){ //不包含此商品
			$map['goods_name']=array('neq',$goods_name);
			$list_count=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('g.order_id,g.goods_nums,o.province,o.city,o.area,o.id,o.order_no,o.logistics_no,o.times,o.add_time,o.user_idcard,o.user_name,o.user_phone,o.user_address')->where($map)->select();
			$count=count($list_count);
			$info=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('g.order_id,g.goods_nums,o.province,o.city,o.area,o.id,o.order_no,o.logistics_no,o.times,o.add_time,o.user_idcard,o.user_name,o.user_phone,o.user_address')->where($map)->limit($firstrow.','.$listrows)->order('id desc')->select();
			
		}
		if($radio_pick==0){
			$count=$m->where($map)->count();
			
			if(empty($map)){
				$info=$m->limit($firstrow.','.$listrows)->order('id desc')->select();
			}else{
				$info=$m->where($map)->limit($firstrow.','.$listrows)->order('id desc')->select();
			}
		}
		
		$Page       = new \Think\Page($count,$listrows);// 实例化分页类 传入总记录数和每页显示的记录数(25)
		$show       = $Page->show();// 分页显示输出
		
		//导出Excel
		$excel=I('excel');
		// echo $p->getlastsql();
		// dump($info);
		// die;

        foreach($info as $k=>$v){
			// $order_info=$p->where(array('order_no'=>$v['order_no']))->find();//取出订单信息
			// echo $p->getlastsql();
			$goods_list=$n->where(array('order_id'=>$v['id']))->select();//取出订单详情商品信息
			// echo $n->getlastsql();
			// dump($goods_list);
			// die;
			$info[$k]['goods_list']=$goods_list;
			
			if(!empty($excel)){ //导出Excel
				$info[$k]['logistics_no']="'".$v['logistics_no'];//转字符串
				$info[$k]['user_phone']="'".$v['user_phone'];//转字符串
				$goods_no="";
				$goods_name="";
				$goods_nums="";
				foreach($goods_list as $keyss=>$valuess){
					if($keyss){
						$goods_no.='/'.$valuess['goods_no'];
					}else{
						$goods_no.="'".$valuess['goods_no'];
					}
					if($keyss){
						$goods_name.='/'.$valuess['goods_name'];
					}else{
						$goods_name.=$valuess['goods_name'];
					}
					if($keyss){
						$goods_nums.='/'.$valuess['goods_nums'];
					}else{
						$goods_nums.=$valuess['goods_nums'];
					}
				}
				$info[$k]['goods_no']=$goods_no;//商品编码
				$info[$k]['goods_name']=$goods_name;//商品名称
				$info[$k]['goods_nums']=$goods_nums;//商品数量
			}
			if(!empty($v['add_time'])){
				$info[$k]['add_time']=date("Y-m-d H:i:s",$v['add_time']);
			}
		}
		
		if(!empty($excel)){ //导出Excel
			$xlsName  = "面单管理";
			$xlsCell  = array(
				array('id','ID'),
				array('order_no','订单编号'),
				array('logistics_no','电子面单号'),
				array('user_name','收件人姓名'),
				array('user_phone','收件人电话'),
				array('province','省'),
				array('city','市'),
				array('area','区'),
				array('user_address','收件人地址'),
				array('times','打印次数'),
				array('add_time','推送时间'),
				array('goods_no','商品编码'),
				array('goods_name','商品名称'),
				array('goods_nums','商品数量')
			);
			$order=A('Order');
			$order->exportExcel($xlsName,$xlsCell,$info);
			die;
		}

        $this->assign("count",$count);
		$this->assign("list",$info);
		$this->assign('page',$show);// 赋值分页输出
		$this->display();
    }
	//出库
	public function outbound_order(){
		$m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		$id=I('id');
		$arr=explode(',',$id);
		$map['id']=array('in',$arr);
		$data['is_delivery']=1;
		$status=$m->where($map)->save($data);
		if($status!==false){
			$return['status']=true;
			$return['message']='出库成功';
			$this->ajaxReturn($return);
		}else{
			$return['status']=false;
			$return['message']='出库失败';
			$this->ajaxReturn($return);
		}
	}
	
	//出库2（运单号）
	public function outbound_order2(){
		$so=M('StorageOutbound', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));//出库记录表
		$ao=M('ArrivalOrder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$m=M('Pushorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$mg=M('Pushordergoods', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$mailNo=I('mailNo');
		$map['logistics_no']=$mailNo;
		$data['is_delivery']=1;
		$data['delivery_time']=time();
		$info=$m->where($map)->find();
		
		// echo $m->getlastsql();
		if(empty($info)){
			$return['status']=false;
			$return['message']='没有查到此运单';
			$this->ajaxReturn($return);
		}else{
			// echo $m->getlastsql();
			if(!$info['times']){
				$return['status']=false;
				$return['message']='此面单未打印，不能出库';
				$this->ajaxReturn($return);
			}else{
				if($info['is_delivery']==1){
					$return['status']=false;
					$return['message']='已出过库,不能再次出库！';
					$this->ajaxReturn($return);
				}else{
					//按企业编码扣费--begin
					// out_money(12,1,16);//12：拣货下架
					// out_money(13,1,16);//13：复核
					// out_money(14,1,16);//14：打印购物清单、运单
					// out_money(15,1,16);//15：商品打包
					// out_money(16,1,16);//16：包裹运单粘贴
					// out_money(17,1,16);//17：包裹出库发货及反馈运单信息
					// out_money(18,1,16);//18：提供包装
					//扣费--end
					$status=$m->where($map)->save($data);
					if($status!==false){
						///////////////////////////////更新批次库存begin
						$info_goods=$mg->where(array('order_id'=>$info['id']))->select();
						foreach($info_goods as $k=>$v){
							$goods_batch_no=explode(',',$v['goods_batch_no']);
							$goods_batch_no=array_filter($goods_batch_no);//去空
							foreach($goods_batch_no as $ks=>$vs){
								$arr=explode(':',$vs);
								$map_ao['id']=$arr[0];
								$data_ao['freez_amount']=array('exp','freez_amount-'.$arr[1]);
								$ao->where($map_ao)->save($data_ao);//更新批次库存表
								$so->add(array('outbound_order_id'=>$info['id'],'inbound_order_id'=>$arr[0],'nums'=>$arr[1],'add_time'=>time(),'out_cate'=>1));//更新出库记录out_cate:(出库类型1:订单出库2:异常出库3:销售单出库数量4:调拨出库5:领料出库)
							}
						}
						/////////////////////////////更新批次库存end
						$return['status']=true;
						$return['message']='出库成功';
						$this->ajaxReturn($return);
					}else{
						$return['status']=false;
						$return['message']='出库失败';
						$this->ajaxReturn($return);
					}
				}
			}
		}
	}
	//自提出库（提货码）
	public function outbound_order_own(){
		$so=M('StorageOutbound',C('DB_PRS'),C('DB_DEPOT'));//出库记录表
		$ao=M('ArrivalOrder',C('DB_PRS'),C('DB_DEPOT'));
		$m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		$mg=M('Pushordergoods',C('DB_PRS'),C('DB_DEPOT'));
		$delivery_code=I('delivery_code');
		$map['delivery_code']=$delivery_code;
		$data['is_delivery']=1;
		$data['delivery_time']=time();
		$info=$m->where($map)->find();
		// echo $m->getlastsql();
		if(empty($info)){
			$return['status']=false;
			$return['message']='没有查到此订单';
			$this->ajaxReturn($return);
		}else{
			// echo $m->getlastsql();
				if($info['is_delivery']==1){
					$return['status']=false;
					$return['message']='已出过库,不能再次出库！';
					$this->ajaxReturn($return);
				}else{
					$status=$m->where($map)->save($data);
					if($status!==false){
						///////////////////////////////更新批次库存begin
						$info_goods=$mg->where(array('order_id'=>$info['id']))->select();
						foreach($info_goods as $k=>$v){
							$goods_batch_no=explode(',',$v['goods_batch_no']);
							$goods_batch_no=array_filter($goods_batch_no);//去空
							foreach($goods_batch_no as $ks=>$vs){
								$arr=explode(':',$vs);
								$map_ao['id']=$arr[0];
								$data_ao['freez_amount']=array('exp','freez_amount-'.$arr[1]);
								$ao->where($map_ao)->save($data_ao);//更新批次库存表
								$so->add(array('outbound_order_id'=>$info['id'],'inbound_order_id'=>$arr[0],'nums'=>$arr[1],'add_time'=>time(),'out_cate'=>1));//更新出库记录out_cate:(出库类型1:订单出库2:异常出库3:销售单出库数量4:调拨出库5:领料出库)
							}
						}
						/////////////////////////////更新批次库存end
						$return['status']=true;
						$return['message']='出库成功';
						$this->ajaxReturn($return);
					}else{
						$return['status']=false;
						$return['message']='出库失败';
						$this->ajaxReturn($return);
					}
				}
			
		}
	}
	//订单列表
	public function pushorderlist(){
        $m=M('Pushorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		
        //搜索条件
        $map=array();
		$map['times']=array('neq',0);
		$map['is_delivery']=1;
        $order_no=I('order_no');
        $user_name=I('user_name');
		$user_phone=I('user_phone');
		$is_delivery=1;

        !empty($order_no)?$map['order_no']=array('like','%'.$order_no.'%'):'';
		!empty($user_name)?$map['user_name']=array('like','%'.$user_name.'%'):'';
		!empty($user_phone)?$map['user_phone']=array('like','%'.$user_phone.'%'):'';

        $p=I('p')?I('p'):1;
		$listrows=20;
		$firstrow=($p-1)*$listrows;
        
        $count=$m->where($map)->count();
        if(empty($map)){
            $info=$m->field('id,id ids,order_no,user_name,user_phone,user_idcard,user_address,is_delivery,logistics_no,logiscompany_name')->limit($firstrow.','.$listrows)->order('id desc')->select();
        }else{
            $info=$m->field('id,id ids,order_no,user_name,user_phone,user_idcard,user_address,is_delivery,logistics_no,logiscompany_name')->where($map)->limit($firstrow.','.$listrows)->order('id desc')->select();
        }
		
        $this->assign("count",$count);
		$this->assign("list",$info);
		$this->assign('page',$show);// 赋值分页输出
		$this->display();
    }
	//自提出库订单列表
	public function get_orderlist_own(){
        $m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
        $ck=A('CheckInput');
		
        //搜索条件
        $map=array();
		// $map['times']=array('neq',0);
		$map['is_delivery']=1;
		$map['transport_cate']=1;
        $order_no=$ck->in('订单编码','order_no','ennumstr','',0,0);        
        $user_name=$ck->in('客户姓名','user_name','cnennumstr','',0,0);
		$user_phone=$ck->in('联系电话','user_phone','ennumstr','',0,0);
		$is_delivery=1;
		// if(!empty($is_delivery)){
			// if($is_delivery==2){
				// $is_delivery=0;
			// }
			// $map['is_delivery']=$is_delivery;
		// }
        !empty($order_no)?$map['order_no']=array('like','%'.$order_no.'%'):'';
		!empty($user_name)?$map['user_name']=array('like','%'.$user_name.'%'):'';
		!empty($user_phone)?$map['user_phone']=array('like','%'.$user_phone.'%'):'';

        $page=$ck->in('当前页','page','intval','1',0,0);   
        $rows=$ck->in('每页记录数','rows','intval','',0,0);  
		
        //排序
        $sort=$ck->in('排序','sort','cnennumstr','delivery_time',0,0);
        $order=$ck->in('规则','order','cnennumstr','desc',0,0);
        
        $count=$m->where($map)->count();
        if(empty($map)){
            $info=$m->field('id,id ids,order_no,user_name,user_phone,user_idcard,user_address,is_delivery,logistics_no,logiscompany_name,delivery_code')->page($page,$rows)->order($sort.' '.$order)->select();
        }else{
            $info=$m->field('id,id ids,order_no,user_name,user_phone,user_idcard,user_address,is_delivery,logistics_no,logiscompany_name,delivery_code')->where($map)->page($page,$rows)->order($sort.' '.$order)->select();
        }
		// echo $m->getlastsql();
		$show_advance=I('show_advance');//显示隐藏信息
		foreach($info as $k=>$v){
			
			if(!$show_advance){
				$info[$k]['user_name']=cut_str($v['user_name'],1,0).'**';
				$info[$k]['user_phone']=substr($v['user_phone'],0,7).'****';
				$info[$k]['user_idcard']=strlen(trim($v['user_idcard']))==0?'无':(strlen($v['user_idcard'])==15?substr_replace($v['user_idcard'],"****",8,4):(strlen($v['user_idcard'])==18?substr_replace($v['user_idcard'],"****",10,4):"身份证位数错误！"));
			}
		}
        if(!empty($info)){
            $data['total']=$count;
            $data['rows']=$info;
        }else{
            $data['total']=0;
            $data['rows']=0;
        }
		
        $this->ajaxReturn($data);
    }
	//订单列表(一般订单)
	public function pushorder(){
		$make_max=C('BASE_CONFIG.make_max');//最大制单数
		$this->assign('make_max',$make_max);

        $m=M('Pushorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$n=M('Pushordergoods', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$model=M('', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		
        //搜索条件
        $map=array();
		$map['pick_status']=0;//未生成波次单
		$map['is_delivery']=0;//未出库
		
		// $map['transport_cate']=array(array('exp','IS NULL'),array('eq',2),'or');
		$map['order_cate']=1;//一般订单
		//拦截
		$inter_list=$this->zintercepted();//拦截订单列表
		$cc=count($inter_list);//拦截订单数量
		if($cc){ //cc大于0，则说明有拦截订单
			foreach($inter_list as $key=>$val){
				$arr[$key]=$val['order_no'];
			}
			$map['order_no']=array('not in',$arr); //移除拦截订单
		}
        $goods_name=I('goods_name','',trim);
		$number=I('nums');
		$radio_pick=I('check_cate');
		 
		$p=I('p')?I('p'):1;
		$listrows=20;
		$firstrow=($p-1)*$listrows;
        
		if($radio_pick==1){ //完全匹配（唯一）
			if($number==''){
				$error_text="数量不能为空";
				$this->error($error_text);
			}
			$map['goods_nums']=$number;
			//生成子查询sql语句
			$sql=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('g.order_id,g.goods_nums,g.goods_name,o.province,o.city,o.area,o.id,o.order_no,o.user_idcard,o.user_name,o.user_phone,o.user_address')->where($map)->buildSql();
			$list_count=$model->table($sql.' a')->group('order_id')->having("count(order_id)=1 and goods_name='$goods_name'")->select();
			$count=count($list_count);
			$info=$model->table($sql.' a')->group('order_id')->having("count(order_id)=1 and goods_name='$goods_name'")->limit($firstrow.','.$listrows)->order('id desc')->select();
			
		}
		if($radio_pick==5){ //商品唯一但不匹配此商品数量
			if($number==''){
				$error_text="数量不能为空";
				$this->error($error_text);
			}
			$map['goods_nums']=array('neq',$number);
			//生成子查询sql语句
			$sql=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('g.order_id,g.goods_nums,g.goods_name,o.province,o.city,o.area,o.id,o.order_no,o.user_idcard,o.user_name,o.user_phone,o.user_address')->where($map)->buildSql();
			$list_count=$model->table($sql.' a')->group('order_id')->having("count(order_id)=1 and goods_name='$goods_name'")->select();
			$count=count($list_count);
			$info=$model->table($sql.' a')->group('order_id')->having("count(order_id)=1 and goods_name='$goods_name'")->limit($firstrow.','.$listrows)->order('id desc')->select();
		}

		if($radio_pick==2){ //包含此商品并且匹配此商品数量
			if($number==''){
				$error_text="数量不能为空";
				$this->error($error_text);
			}
			$map['goods_nums']=$number;
			//生成子查询sql语句
			$sql=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('g.order_id,g.goods_nums,g.goods_name,o.province,o.city,o.area,o.id,o.order_no,o.user_idcard,o.user_name,o.user_phone,o.user_address')->where($map)->buildSql();
			$list_count=$model->table($sql.' a')->group('order_id')->having("count(order_id)<>1 and goods_name='$goods_name'")->select();
			$count=count($list_count);
			$info=$model->table($sql.' a')->group('order_id')->having("count(order_id)<>1 and goods_name='$goods_name'")->limit($firstrow.','.$listrows)->order('id desc')->select();
			// echo $model->getlastsql();
		}
		if($radio_pick==3){ //包含此商品但不匹配此商品数量
			if($number==''){
				$error_text="数量不能为空";
				$this->error($error_text);
			}
			$map['goods_nums']=array('neq',$number);
			//生成子查询sql语句
			$sql=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('g.order_id,g.goods_nums,g.goods_name,o.province,o.city,o.area,o.id,o.order_no,o.user_idcard,o.user_name,o.user_phone,o.user_address')->where($map)->buildSql();
			$list_count=$model->table($sql.' a')->group('order_id')->having("count(order_id)<>1 and goods_name='$goods_name'")->select();
			$count=count($list_count);
			$info=$model->table($sql.' a')->group('order_id')->having("count(order_id)<>1 and goods_name='$goods_name'")->limit($firstrow.','.$listrows)->order('id desc')->select();
		}
		if($radio_pick==4){ //不包含此商品
			$map['goods_name']=array('neq',$goods_name);
			$list_count=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('g.order_id,g.goods_nums,o.province,o.city,o.area,o.id,o.order_no,o.user_idcard,o.user_name,o.user_phone,o.user_address')->where($map)->select();
			$count=count($list_count);
			$info=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('g.order_id,g.goods_nums,o.province,o.city,o.area,o.id,o.order_no,o.user_idcard,o.user_name,o.user_phone,o.user_address')->where($map)->limit($firstrow.','.$listrows)->order('id desc')->select();
			
		}
		
		if($radio_pick==0){
			$count=$m->where($map)->count();
			
			if(empty($map)){
				$info=$m->limit($firstrow.','.$listrows)->order('id desc')->select();
			}else{
				$info=$m->where($map)->limit($firstrow.','.$listrows)->order('id desc')->select();
			}
		}
		$Page       = new \Think\Page($count,$listrows);// 实例化分页类 传入总记录数和每页显示的记录数(25)
		$show       = $Page->show();// 分页显示输出
		// echo $m->getlastsql();
		// die;
		foreach($info as $k=>$v){
			$s=M('Storage', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
			$storage_info=$s->where(array('storage_code'=>$v['storage_code']))->find();
			$info[$k]['storage_code']=$storage_info['name'];
		}
		// dump($info);
        $this->assign("count",$count);
		$this->assign("list",$info);
		$this->assign('page',$show);// 赋值分页输出
		$this->display();
    }
	
	//拣货单商品汇总
	public function pickcollect(){
		$this->display();
	}
	//生成拣货单汇总商品数据
	public function make_pickcollect(){		
		$m=M('Pickcollect', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$n=M('Pushorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$k=M('Pushordergoods', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$ao=M('ArrivalOrder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		// $model=M('', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$sql = 'truncate table '.C('erp_dbname').'.'.C('DB_PREFIX_T').'pickcollect';
		$stat=M()->execute($sql);//清空汇总表
		// echo M()->getlastsql();
		// die;
		
		$id=I('id');
		$map['order_id']  = array('in',$id);
		$maps['id']  = array('in',$id);
		
		$ordernolist=$n->field('order_no,pick_status,is_delivery')->where($maps)->select();
		// echo $n->getlastsql();
		foreach($ordernolist as $key=>$value){
			if($value['pick_status']==1 or $value['is_delivery']==1){//校检
				$return['message']="订单".$value['order_no']."已生成过波次单或已出库,不能再次生成!";
				$return['status']=false;
				$this->ajaxReturn($return);
			}
			if(!$key){
				$orderlist=$orderlist.$value['order_no'];
			}else{
				$orderlist=$orderlist.','.$value['order_no'];
			}
		}

		$list=$k->field('goods_no,goods_name,sum(goods_nums) goods_count')->group('goods_no')->where($map)->select();
		// echo $k->getlastsql();
		foreach($list as $keys=>$v){
			$data['goods_no']	=$v['goods_no'];
			$data['goods_name']	=$v['goods_name'];
			$data['goods_count']=$v['goods_count'];
			$ao_list=$ao->field('storage_code')->where(array('goods_no'=>$v['goods_no'],'grounding_status'=>1))->select();
			
			$data['storage_code']	=$ao_list[0]['storage_code'];
			$data['storage_level']	=10;
			
			$status=$m->add($data);
			// echo $m->getlastsql();
			if(!$status){
				$return['message']="生成出错";
				$return['status']=false;
				$this->ajaxReturn($return);
				exit;
			}
		}

		$return['message']="生成成功！";
		$return['orderlist']=$orderlist;
		$return['status']=true;
		$this->ajaxReturn($return);
	}
	
	//拣货单商品汇总
	public function get_pickcollect(){
		$m=M('Pickcollect', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$Storage=M('Storage', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$p=I('p')?I('p'):1;
		$listrows=20;
		$firstrow=($p-1)*$listrows;
		//获取数据
		$count=$m->count();
        $info=$m->order('id')->select();
		foreach($info as $k=>$v){
			$storage_info=$Storage->where(array('storage_code'=>$v['storage_code']))->find();
			$info[$k]['storage_code']=$storage_info['name'];
		}
		$orderlist=I('orderlist');
		$orderlist=str_replace(',','/',$orderlist);
		$Page       = new \Think\Page($count,$listrows);// 实例化分页类 传入总记录数和每页显示的记录数(25)
		$show       = $Page->show();// 分页显示输出
		$this->assign("count",$count);
		$this->assign("list",$info);
		$this->assign("orderlist",$orderlist);
		$this->assign('page',$show);// 赋值分页输出
		$this->display();
	}
	//历史波次单
	//获得历史波次单列表
	public function historypicklist(){
		//参数验证
		$m=M('Picklist', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
        $picklist_no=I('picklist_no');
		$p=I('p')?I('p'):1;
		$listrows=20;
		$firstrow=($p-1)*$listrows;
		//搜索条件
		$map=array();
		
		!empty($picklist_no)?$map['picklist_no']=array('like','%'.$picklist_no.'%'):'';
		
		$count=$m->where($map)->count();
		$list=$m->where($map)->limit($firstrow.','.$listrows)->order('id desc')->select();
		$Page       = new \Think\Page($count,$listrows);// 实例化分页类 传入总记录数和每页显示的记录数(25)
		$show       = $Page->show();// 分页显示输出
		
        $this->assign("count",$count);
		$this->assign("list",$list);
		$this->assign('page',$show);// 赋值分页输出
		$this->display();
	}
	//波次单查看
	public function picklistView(){
		$id=I('id');
		$m=M('Picklist', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$Storage=M('Storage', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$n=M('Pickorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$p=M('Pushorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$gg=M('Pushordergoods', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$pr=M('Printorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$Pickgoods=M('Pickgoods', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$country=M('Country', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$picklist_info=$m->find($id);
		// echo $m->getlastsql();
		$picklist_no=$picklist_info['picklist_no'];
		
		$Pickorder_list=$n->where('picklist_no="'.$picklist_no.'"')->select();
		// dump($picklist_info);
		// die;
		$Pickgoods_list=$Pickgoods->where('picklist_no="'.$picklist_no.'"')->select();
		foreach($Pickgoods_list as $ks=>$vs){
			$storage_info=$Storage->where(array('storage_code'=>$vs['storage_code']))->find();
			$Pickgoods_list[$ks]['storage_code']=$storage_info['name'];
		}
		// echo $Pickgoods->getlastsql();
		foreach($Pickorder_list as $key => $v){
			$list=$p->field('order_no,logistics_no')->where('id='.$v['order_id'])->find();
			
			$list_print=$pr->where('order_no="'.$list['order_no'].'"')->find();//获取物流单号
			$Pickorder_list[$key]['order_no']=$list['order_no'];
			$Pickorder_list[$key]['mailNo']=$list['logistics_no'];
			/********显示订单商品明细************/
			$Pickorder_list[$key]['goods']=$gg->where('order_id='.$v['order_id'])->select();
			foreach($Pickorder_list[$key]['goods'] as $k=>$value){
				$Pickorder_list[$key]['goods'][$k]['country_name']=$country->where(array('country_code'=>$value['source']))->find();
				$Pickorder_list[$key]['goods'][$k]['country_name']=$country->where(array('country_code'=>$value['source']))->find();
			}
		}
		// dump($Pickgoods_list);
		// die;
		$this->assign('picklist_no',$picklist_no);
		$this->assign('pickorder_list',$Pickorder_list);
		$this->assign('Pickgoods_list',$Pickgoods_list);
		$this->display();
	}
	//获得订单商品
	public function get_pickordergoods(){
		$g=M('Pushordergoods',C('DB_PRS'),C('DB_DEPOT'));
		$order_id=I('order_id');
		$pickordergoods_list=$g->where(array('order_id'=>$order_id))->select();
		// dump($pickordergoods_list);
		$this->ajaxReturn($pickordergoods_list);
	}
	//获得波次单商品
	public function get_pickgoods(){
		$g=M('Pickgoods',C('DB_PRS'),C('DB_DEPOT'));
		$picklist_no=I('picklist_no');
		$pickgoods_list=$g->where(array('picklist_no'=>$picklist_no))->select();
		$this->ajaxReturn($pickgoods_list);
	}
	//流水号
	public function serialNumber($tablename){
		$m=M($tablename, C('DB_PREFIX_T'), C('db_config'));
		//当日流水号生成
		$map['_string']="add_time-UNIX_TIMESTAMP(DATE(NOW()))>0 and add_time-UNIX_TIMESTAMP(DATE(NOW()))<86400";
		$count=$m->where($map)->count();//当天添加的采购单数
		
		$count=$count+1;
		$serial_number="";
		if($count<10){
			$serial_number='0000'.strval($count);
		}
		if($count>=10 and $count<100){
			$serial_number='000'.$count;
		}
		if($count>=100 and $count<1000){
			$serial_number='00'.$count;
		}
		if($count>=1000 and $count<10000){
			$serial_number='0'.$count;
		}
		return $serial_number;//流水序号
	}
	//按批次号冻结库存
	//ao_info批次详情
	//vs订单商品详情
	//自动关联批次库存
	public function freez_storage($vs=array()){
		$ao=M('ArrivalOrder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));//商品详情入库单
		$pog=M('Pushordergoods', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));//订单详情表
		
		$ao_info=$ao->where(array('goods_no'=>$vs['goods_no'],'storage_amount'=>array('GT',0)))->order('add_time asc')->limit(1)->find();//按商品入库批次顺序冻结库存
		
		// if(empty($ao_info)){
			// $return['message']="没有找到库存商品，不能进行下面的操作！";
			// $return['status']=false;
			// return $return;
		// }
		$map_ao['id']=$ao_info['id'];//条件
		if($ao_info['storage_amount']>=$vs['goods_nums']){//剩余库存大于等于订单商品数量
			$data_ao['freez_amount']=array('exp','freez_amount+'.$vs['goods_nums']);//冻结数量
			$data_ao['storage_amount']=array('exp','storage_amount-'.$vs['goods_nums']);//更新库存
			$res_ao=$ao->where($map_ao)->save($data_ao);//更新
			
			$map_pog['id']=$vs['id'];
			$str=$ao_info['id'].':'.$vs['goods_nums'];
			$data_pog['goods_batch_no']=array('exp',"concat(goods_batch_no,',$str')");//关联批次和数量
			$pog->where($map_pog)->save($data_pog);//更新
			// echo $pog->getlastsql();
			// die;
			$return['message']="更新成功";
			$return['status']=true;
			return $return;
		}else{
			$data_ao['freez_amount']=array('exp','freez_amount+'.$ao_info['storage_amount']);//冻结数量
			$data_ao['storage_amount']=0;//更新库存
			$res_ao=$ao->where($map_ao)->save($data_ao);//更新
			
			$map_pog['id']=$vs['id'];
			$str=$ao_info['id'].':'.$vs['goods_nums'];
			$data_pog['goods_batch_no']=array('exp',"concat(goods_batch_no,',$str')");//关联批次和数量
			$pog->where($map_pog)->save($data_pog);//更新
			// echo $pog->getlastsql();
			// die;
			$vs['goods_nums']=$vs['goods_nums']-$ao_info['storage_amount'];//剩余数量
			return $this->freez_storage($vs);//递归调用
		}
	}
	//生成拣货单
	public function makepicklist(){
		$ao=M('ArrivalOrder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));//商品详情入库单
		
		$orderlist=I('orderlist');
		$arr=explode('/',$orderlist);
		$this->haspicklist($arr);//判断是否已生成波次单
		$m=M('Picklist', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$n=M('Pickgoods', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$p=M('Pickorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$g=M('Pickcollect', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$po=M('Pushorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$pog=M('Pushordergoods', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		$t_no=$this->serialNumber('Picklist');//流水号
		$picklist_no='P'.date('Ymd',time()).$t_no;//拣货单号
		$dataa['status']=1;
	    $dataa['add_time']=time();
	    $dataa['picklist_no']=$picklist_no;
		$status=$m->add($dataa);//添加拣货单数据
		
		if($status){
			$list=$g->select();
			foreach($list as $k=>$v){
				$data['goods_name']=$v['goods_name'];
				$data['goods_no']=$v['goods_no'];
				$data['goods_count']=$v['goods_count'];
				// $data['storage_code']=$v['storage_code'];
				$data['storage_level']=$v['storage_level'];
				$data['add_time']=time();
				$data['picklist_no']=$picklist_no;
				if(empty($v['goods_no'])){
				   $return['message']="存在商品编码为空的商品";
				   $return['status']=false;
				   $this->ajaxReturn($return);
				}
				if(empty($v['goods_name'])){
				   $return['message']="存在商品名称为空的商品";
				   $return['status']=false;
				   $this->ajaxReturn($return);
				}
				if(empty($v['goods_count'])){
				   $return['message']="存在商品数量为空的商品";
				   $return['status']=false;
				   $this->ajaxReturn($return);
				}
				// if(empty($v['storage_code'])){
				   // $return['message']="存在库位为空的商品";
				   // $return['status']=false;
				   // $this->ajaxReturn($return);
				// }
				
				if($n->add($data)){
					// echo $n->getlastsql();
					continue;
				}else{
				   $return['message']="生成对应商品数据失败";
				   $return['status']=false;
				   $this->ajaxReturn($return);
				}
			}
			
			$data_order['picklist_no']=$picklist_no;
			$data_order['add_time']=time();
			foreach($arr as $key=>$value){
				$orderid=$po->field('id')->where('order_no="'.trim($value).'"')->find();
				$pog_list=$pog->where(array('order_id'=>$orderid['id']))->select();//获得商品详情
				// dump($pog_list);
				// die;
				//自动关联批次-begin
				// foreach($pog_list as $ks=>$vs){
					// $freez_status=$this->freez_storage($vs);//调用递归函数,自动关联批次库存
					// if($freez_status['status']){
						// continue;
					// }else{
						// $this->ajaxReturn($freez_status);
					// }
				// }
				//自动关联批次-end
				$data_po['pick_status']=1;//更新订单拣货状态
				$data_po['box_no']=$key+1;//关联拣货筐号
				$po->where('order_no="'.trim($value).'"')->save($data_po);
				$data_order['order_id']=$orderid['id'];
				$res=$p->add($data_order);
				
				if($res){
					continue;
				}else{
					$return['message']="生成对应订单数据失败";
				    $return['status']=false;
				    $this->ajaxReturn($return);
				}
			}
		}else{
			$return['message']="生成波次单失败";
			$return['status']=false;
			$this->ajaxReturn($return);
		}
		$return['message']="生成波次单成功";
		$return['picklist_id']=$status;
		$return['status']=true;
		$this->ajaxReturn($return);
	}
	
	//确认上架
    public function confirm_grounding(){
		$m=M('Goods',C('DB_PRS'),C('DB_DEPOT'));
        if(!IS_POST) exit; 
        $ck=A('CheckInput');
        $data['bar_code']=$ck->in('条形码','bar_code','ennumstr','',2,30);
		$data['storage_code']=$ck->in('库位','storage_code','ennumstr','',1,10);
		$data['grounding_status']=1;
        $map['id']=$ck->in('erp企业id','id','intval','',1,0);
		
        $result=$m->where($map)->save($data);

        if(false===$result){
            $return['message']='上架失败';
            $return['status']=false;
            $this->ajaxReturn($return);
        }else{
			$return['message']='上架成功!';
			$return['status']=true; 
			$this->ajaxReturn($return);
        }
    }
	//批量下架
    public function ungrounding(){
		$m=M('Goods',C('DB_PRS'),C('DB_DEPOT'));
        if(!IS_POST) exit; 
        $ck=A('CheckInput'); 
        $id=$ck->in('库存商品id','id','string','',1,0);
        if(empty($id)) exit;//为空
        $arr=explode(',', $id);
        $map['id']=array('in',$arr);
		$data['storage_code']=0;
		$data['grounding_status']=0;
        $result=$m->where($map)->save($data);
        if($result===false){
            $return['message']='下架失败!';
            $return['status']=false;  
        }else{
            $return['message']='下架成功!';
            $return['status']=true; 
        }        
        $this->ajaxReturn($return);
    }
	//订单检查，是否已经生成波次单
	// public function checkpick(){
	    // $ids=I('ids');
	    // foreach($ids as $k=>$v){
		    // $res=M('Pickorder',C('DB_PRS'),C('DB_DEPOT'))->where('order_id='.$v)->find();
		    // if($res){
			   // $order=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'))->where('id='.$res['order_id'])->find();
			   // $this->error('订单:'.$order['order_no'].'已经生成过波次单！请重新选择订单！');
		    // }else{
			   // $this->success('订单检查通过，没有已生成波次单的订单');
		    // }
	    // }
	// }
	//是否已经生成过波次单
	public function haspicklist($list){
		foreach($list as $k=>$v){
		   $res=M('Pushorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'))->where('order_no="'.$v.'"')->find();
		   if($res){
			   $status=M('Pickorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'))->where('order_id='.$res['id'])->find();
			   if($status){
				   $return['message']='订单:'.$v.'已经生成过波次单！请重新选择订单！';
				   $return['status']=false;
				   $this->ajaxReturn($return);
			   }
			}
		}
	}
	// public function printbat_iframe(){
		// $id=I('id');
		// $iframeUrl=U('printbat',array('id'=>$id));
		// $this->assign('iframeUrl',$iframeUrl);
		// $this->display();
	// }
	// public function printbatSF_iframe(){
		// $id=I('id');
		// $iframeUrl=U('printbatSF',array('id'=>$id));
		// $this->assign('iframeUrl',$iframeUrl);
		// $this->display();
	// }
	//批量打印百世面单
	// public function printbat(){
	  // $id=I('id');
	  // $m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
	  // $n=M('Printorder',C('DB_PRS'),C('DB_DEPOT'));
	  // $printerid_list=explode(',',$id);
	  // $map['id']=array('in',$printerid_list);
	  // $printorder_list=$n->where($map)->select();
	  // $this->assign('printorder_list',$printorder_list);
	  // $this->display();
	// }
	//批量打印顺丰面单
	// public function printbatSF(){
	  // $id=I('id');
	  // $n=M('Printorder',C('DB_PRS'),C('DB_DEPOT'));
	  // $g=M('Pushordergoods',C('DB_PRS'),C('DB_DEPOT'));
	  // $p=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
	  // $printerid_list=explode(',',$id);
	  // $map['id']=array('in',$printerid_list);
	  // $printorder_list=$n->where($map)->select();
	  // foreach($printorder_list as $k=>$v){
		  // $order_info=$p->field('id')->where(array('order_no'=>$v['order_no']))->find();
		  // $order_id=$order_info['id'];
		  // $goods_info=$g->where(array('order_id'=>$order_id))->limit(2)->select();
		  // $printorder_list[$k]['goods_info']=$goods_info;
	  // }
	  // $this->assign('printorder_list',$printorder_list);
	  // $this->display();
	// }
	
	//批量打印顺丰面单--预览/直接打印
	public function ajax_printbatSF(){
	  $id=I('id');
	  $preview=I('preview');//预览参数
	  // $m=M('Pushorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
	  $n=M('Printorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
	  $g=M('Pushordergoods', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
	  $p=M('Pushorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
	  $printerid_list=$id;
	  $map['id']=array('in',$printerid_list);
	  $order_list=$p->field('order_no')->where($map)->select();//订单列表
	  foreach($order_list as $keys=>$values){
		  $order_no_list[$keys]=$values['order_no'];
	  }
	  
	  $mapss['order_no']=array('in',$order_no_list);
	  $printorder_list=$n->where($mapss)->group('order_no')->select();
	  
	  // echo $n->getlastsql();
	  if(empty($preview)){//非预览状态
		  $p->where($map)->save(array('printer_name'=>session('username'),'times'=>array('exp','times+1')));//更新打印次数
	  }
	  
	  // dump($printorder_list);
	  // die;
	  foreach($printorder_list as $k=>$v){
		  $order_info=$p->field('id')->where(array('order_no'=>$v['order_no']))->find();
		  $order_id=$order_info['id'];
		  $goods_info=$g->where(array('order_id'=>$order_id))->select();
		  // $printorder_list[$k]['goods_info']=$goods_info;
		  $goods_text_head	='<p style="font-size:10px;line-height:12px;">';
		  $goods_text_body="";
		  foreach($goods_info as $ks=>$vs){
			 $goods_text_body.=$vs['goods_name'].'|'.$vs['goods_nums'];
		  }
		  $goods_text_body2=msubstr($goods_text_body,0,71,'utf-8',false);
		  $goods_text=$goods_text_head.$goods_text_body2.'</p>';
		  $text_head='<!DOCTYPE html>
						<html lang="zh-CN">
						<head>
							<meta charset="UTF-8">
							<meta http-equiv="X-UA-Compatible" content="IE=edge">
							<title>顺丰打印单</title>
							<link rel="icon" href="">
							<link rel="stylesheet" href="./Public/sf/css/common.css">
							<link rel="stylesheet" href="./Public/sf/css/style.css">
							<script type="text/javascript" src="./Public/Admin/lib/jquery/1.9.1/jquery.min.js"></script>
						<style rel="stylesheet" type="text/css" media="all" />
							@media print {
							.noprint { display: none; }
							.break {page-break-after:always;}
							}
						</style>
						</head>
						<body>';
			$text_end='<div class="break" style="page-break-before:always;width:100%;height:0px;clear:both;">&nbsp;</div></body>';
			$text_body='<div class="page">
		<input type="hidden" class="order_no" value="'.$v['order_no'].'" name="order_no" />
		<div class="m1 b">
		</div>
		<div class="m2 b">
			<div class="left">
			<img width="235.3px" height="60px" src="/Public/plugins/barcodegen/test_1D.php?text='.$v['mailno'].'" alt="barcode"/>
				<p>单号<span>'.$v['mailno'].'</span></p>
			</div>
			<div class="right">
				<div class="r1 b" >
					<p style="font-size:14px">云仓专配次日</p>
				</div>
				<div class="r2">
					<p class="p1"></p>
					<p class="p2">月结卡号：'.$v["custid"].'</p>
                    <p class="p2">付款方式:'.$v["pay_methods"].'</p>
				</div>
			</div>
		</div>
		<div class="m3 b">
			<div class="left">
				<p>目的地</p>
			</div>
			<div class="right">
				<p align="center">'.$v["destcode"].'</p>
			</div>
		</div>
		<div class="m4 b">
			<div class="left">
				<p>收件人</p>
			</div>
			<div class="right" >
				<p>
                 '.$v["receiveman"].'
                 </p>
				<p>电话:'.$v["receivemanphone"].'</p>
				<p>'.$v["receiveprovince"].$v["receivecity"].$v["receivecounty"].$v["receivemanaddress"].'</p>
			</div>
		</div>
		<div class="m5 b">
			<div class="left">
				<p>寄件人</p>
			</div>
			<div class="right-1" style="font-size:15px">
				<p>'.$v["sendman"].'</p>
				<p>电话:'.$v["sendManPhone"].'</p>
				<p>'.$v["sendprovince"].$v["sendcity"].$v["sendcounty"].$v["sendmanaddress"].'</p>
			</div>
			<div class="right-2">
				<p class="p1" style="font-size:13px">定时派送</p>
				<p class="p2">自寄 </p>
			</div>
		</div>
		<div class="m6 b cl">
			<div class="left">

				<div class="l2">
					<div class="l2-a">
						<p>托寄物</p>
					</div>
					<div class="l2-b">
					'.$goods_text.'
                     </div>
					<div class="l2-c">
						<ul>
							<li>收件员：</li>
							<li>收件日期：</li>
							<li>派件员：</li>
						</ul>
					</div>
				</div>
			</div>
			<div class="right">
				<p>签名：</p>
				<p class="p2">月<span>日</span></p>
			</div>
		</div>
		<div class="item b">
			<div class="m7 b cl">
				<div class="left">
					<img class="img1" src="./Public/sf/img/logo.jpg">
					<img src="./Public/sf/img/tel.png">
				</div>
				<div class="right">
				<img style="margin-top:10px" width="162.9px" height="48.2px;" src="/Public/plugins/barcodegen/test_1D.php?text='.$v['mailno'].'" alt="barcode"/>
				</div>
			</div>
			<div class="m5 b">
				<div class="left">
					<p>寄件人</p>
				</div>
				<div class="right" >
					<p>'.$v["sendman"].'    '.$v["sendmanphone"].'</p>
					<p>'.$v["sendprovince"].$v["sendcity"].$v["sendcounty"].$v["sendmanaddress"].'</p>
				</div>
			</div>
			<div class="m5 b">
				<div class="left">
					<p>收件人</p>
				</div>
				<div class="right" style="width:95%">
                    <p>'.$v["receiveman"].'&nbsp'.$v["receivemanphone"].'</p>
                    <p>'.$v["receiveprovince"].$v["receivecity"].$v["receivecounty"].$v["receivemanaddress"].'</p>
				</div>
			</div>
            <div class="m10" style="height:50px">
                <p class="s2"  align="center">农宇--G20食材专供工厂</p>
            </div>
		</div>
	</div>';
		$text[$k]=$text_head.$text_body.$text_end;  
	  }
	 
	  $return['status']=1;
	  $return['info']=$text;
	  $this->ajaxReturn($return);
	}
	//批量打印百世面单--预览/直接打印
	public function ajax_printbatBS(){
	  $id=I('id');
	  $preview=I('preview');
	  // $m=M('Pushorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
	  $n=M('Printorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
	  $g=M('Pushordergoods', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
	  $p=M('Pushorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
	  $printerid_list=$id;
	  $map['id']=array('in',$printerid_list);
	  $order_list=$p->field('order_no')->where($map)->select();//订单列表
	  foreach($order_list as $keys=>$values){
		  $order_no_list[$keys]=$values['order_no'];
	  }
	  
	  $mapss['order_no']=array('in',$order_no_list);
	  $printorder_list=$n->where($mapss)->group('order_no')->select();
	  // echo $n->getlastsql();
	  if(empty($preview)){//非预览状态
		  $p->where($map)->save(array('printer_name'=>session('username'),'times'=>array('exp','times+1')));//更新打印次数
	  }
	  
	  //dump($printorder_list);
	  //die;
	  foreach($printorder_list as $k=>$v){
		  $order_info=$p->field('id,box_no')->where(array('order_no'=>$v['order_no']))->find();
		  $order_id=$order_info['id'];
		  $goods_info=$g->where(array('order_id'=>$order_id))->limit(20)->select();
		  // $printorder_list[$k]['goods_info']=$goods_info;
		  $count=count($goods_info);
		  foreach($goods_info as $ks=>$vs){
			 $goods_text='<p style="font-size: 12px;">'.msubstr($vs['goods_name'],0,12).'</p>
                        <p style="font-size: 12px;">数量:'.$vs['goods_nums'].'</p>';
		  }
		  $text_head='<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>百世面单</title>
<style rel="stylesheet" type="text/css" media="all" >
body {
margin:0 9px 9px 9px;
width:450px;
padding: 0;
color: black;
text-decoration: none;
font-size: 11pt;
font-weight:bold;
font-family: "Courier New";
}
.ems input {
	font-family: Arial;
}

.ems th {
	font-weight: normal;
	border-bottom: 1px solid black;
}

.ems td {
	font-size: 9pt;
	font-family: "Courier New";
}

.ems td.pod {
	font-size: 11pt;
	font-family: "Courier New";
}

.ems td.t1{
	font-size:1pt;
	font-family:"宋体";
}
.ems th.pod {
	font-size: 11pt;
	font-family: "Courier New";
}

.ems td.endline {
	border-top: 1px solid black;
}

.ems .left {
	text-align: left;
}

.ems .right {
	text-align: right;
}

.ems .center {
	text-align: center;
}

.ems .top {
	vertical-align: top;
}

@media print {
	.break {page-break-after:always;}
}

</style>
<script type="text/javascript" src="./Public/Admin/lib/jquery/1.9.1/jquery.min.js"></script>
</head>

<body>';
			$text_end='<div class="break" style="page-break-before:always;width:100%;height:0px;clear:both;">&nbsp;</div></body>';
			$text_body='<table id="emstable" cellspacing="0" style="margin-left:0;margin-top:1px;float:left;width:380px;font-size:11pt;float: left;">
	<tr style="width: 330px;" height="40.2px">
		<td width="192px" style="border-bottom: 1px solid #000;vertical-align:top;">
		</td>

		<td width="170px" style="border-bottom: 1px solid #000;">
			<div>
				<span style="font-family: \'黑体\';font-size: 12pt;">标准快递</span><br>
				<span style="font-family: \'黑体\';font-size: 12pt;">成就商业•精彩生活</span><br>
			</div>
		</td>
	</tr>
	<tr>
		<td colspan="2">
			<table   width="368px";cellspacing="0" cellpadding="0" style="margin-left: 10px;border-bottom: 1px solid #000;">
				<tr>
					<td width="270px" height="40px" >
						<div style="width:270px;height: 40px;">
							<b><span style="font-family: \'黑体\';font-size: 26pt;">'.$v["destcode"].'</span></b>
						</div>
					</td>
					<td width="40px">
						<div style="width: 50px; height:40px;">
							<b><span style="font-family: \'黑体\';font-size: 26pt;">'.$v["sortingcode"].'</span></b><br>
						</div>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	
	<tr>
		<td colspan="2">
			<table   width="368px";cellspacing="0" cellpadding="0" style="margin-left: 10px;border-bottom: 1px solid #000;">
				<tr>
					<td width="330px" height="40px">
						<div style="width:330px;">
							<b style="float:left;"><span style="font-family: \'黑体\';font-size: 20pt;">'.$v["pkgcode"].'</span></b>
							<span style="margin-top:4px;float:right;font-size:10px;">
								订单号：'.$v["order_no"].'<br>件数:'.$count.'
							</span>
						</div>
					
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
			<td colspan="2">
			<table width="330px"; cellspacing="0" style="padding-left: 10px;">
				<tr>
					<td  width="14px"; height="65px" style="border-right: 1px solid #000;border-bottom: 1px solid #000;">
						<div style="width: 14px; height: 65px;">
							<span>收件</span>
						</div>
					</td>

					<td width="237.85px" height="65px" style="border-right: 1px solid #000;border-bottom: 1px solid #000; ">
						<div style="width: 237.85px; height: 65px; padding: 0px;line-height: 16px;">
							<span style="font-family: \'宋体\';font-size: 10pt;">'.$v["receiveman"].'</span><br>
							<span style="font-family: \'宋体\';font-size: 10pt;">电话：'.$v["receivemanphone"].'</span><br>
							<span style="font-family: \'宋体\';font-size: 10pt;">地址：'.$v["receiveprovince"].$v["receivecity"].$v["receivecounty"].$v["receivemanaddress"].'</span>

						</div>
					</td>
					
			
					<td rowspan="2" width="100px" style="border-bottom: 1px solid #000;">

							<div style="width: 105px; height: 130px; padding: 0; margin: 0;">
							<table  width="105px"; cellspacing="0" height="130px" >
								<tr >
									<td style="width:105px;height: 24.17px; text-align: center; border-bottom: 1px solid #000;">
										<div  style="width:105px;height: 24.17px;">
											<span>服务</span>
										</div>
									</td>
								</tr>
								<tr>
									<td style="width:107px;float:left;">
										<div style="width:107px;float:left;">
											<span style="font-family: \'宋体\';font-size: 10pt;float:left;">代付/到付：代付</span><br>
											<span style="font-family: \'宋体\';font-size: 10pt;float:left;">保价金额：0元</span><br>
											<span style="font-family: \'宋体\';font-size: 10pt;float:left;">报价费用：0元</span><br>
											<span style="font-family: \'宋体\';font-size: 10pt;float:left;">其他说明：</span>
										</div>
									</td>
								</tr>
							</table>
						</div>
					</td>
				</tr>
				<tr>
					<td  width="330px"; height="65px" style="border-right: 1px solid #000;border-bottom: 1px solid #000;">
						<div style="width: 14px; height: 65px;">
						<span>寄件</span></td>
						</div>
					<td width="237.85px" height="65px" style="border-right: 1px solid #000;border-bottom: 1px solid #000;line-height: 16px;">
						<div style="width: 237.85px; height: 65px;">
							<span style="font-family: \'宋体\';font-size: 10pt;">'.$v["sendman"].'</span><br>
							<span style="font-family: \'宋体\';font-size: 10pt;">电话：'.$v["sendmanphone"].'</span><br>
							<span style="font-family: \'宋体\';font-size: 10pt;">地址：'.$v["sendprovince"].$v["sendcity"].$v["sendcounty"].$v["sendmanaddress"].'</span>
						</div>
					</td>
				</tr>
			</table>
			</td>
	</tr>
	<tr>
		<td width="330px" style="border-bottom: 1px solid #000;" colspan="2">
			<table width="330px" style="margin-left: 10px;" >
				<tr>
					<td width="330px">
						<div style="width:235.3px;height: 65px; text-align: center; margin: 0 auto;">
							<img width="235.3px" height="65px" src="/Public/plugins/barcodegen/test_1D.php?text='.$v['mailno'].'" alt="barcode"/>
							
						</div>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td width="330px" height="50px" colspan="2">

			<div style="height: 50px;">
				<table width="330px"; cellspacing="0" style="margin-left: 10px;">
					<tr>
							<td width="200px" height="50px" style="border-top: 1px solid #000;border-right: 1px solid #000;border-bottom: 1px solid #000;">

								<div style="width: 200px; height: 50px;font-size:12px;">
								您对此单的签收，代表您已验收，确认商品信息无误，包装完好、没有划痕、破损等表面质量问题。
							</div>
						</td>
						<td width="90px" height="50px" style="border-top: 1px solid #000;border-right: 1px solid #000;border-bottom: 1px solid #000;" cellpadding="0" cellspacing="0">
							<div style="width: 90px; height: 50px;">
								<span style="font-family: \'宋体\';font-size: 10pt;">收件人</span><br><br>
								<span style="font-family: \'宋体\';font-size: 10pt;">时间</span>
							</div>
						</td>
						<td  width="68px" height="50px" style="border-top: 1px solid #000;border-bottom: 1px solid #000;">
							<div style="width:68px;height: 50px;">
								
							</div>
						</td>
					</tr>
				</table>
				
			</div>
		</td>
	</tr>
	<tr>
		<td colspan="2">
		<table width="368px" height="60.3px" style="border-bottom: 1px solid #000; margin-left: 10px;padding-top:18px;">
			<tr>
				<td width="200px" height="60.3px"></td>
				<td width="162.9px" height="60.3px">
					<div style="width;162.9px; height: 48.2px;margin-right:10px;">
						<img width="162.9px" height="48.2px;" src="/Public/plugins/barcodegen/test_1D.php?text='.$v['mailno'].'" alt="barcode"/>
					</div>
				</td>
			</tr>		
		</table>
		</td>
	</tr>
	<tr>
		<td colspan="2">
		<table width="330px"; height="120.7px" cellspacing="0" style="padding-left: 10px;">
			<tr>
				<td  width="14px"; height="60.3px" style="border-right: 1px solid #000;border-bottom: 1px solid #000;">
					<div style="width: 14px; height: 60.3px;">
						<span>收件</span>
					</div>
				</td>
				<td width="237.85px" height="65px" style="border-right: 1px solid #000;border-bottom: 1px solid #000;">
					<div style="width: 237.85px; height: 65px;line-height:15px;">
						<span style="font-family: \'宋体\';font-size: 10pt;">'.$v["receiveman"].'</span><br>
						<span style="font-family: \'宋体\';font-size: 10pt;">电话：'.$v["receivemanphone"].'</span><br>
						<span style="font-family: \'宋体\';font-size: 10pt;">地址：'.$v["receiveprovince"].$v["receivecity"].$v["receivecounty"].$v["receivemanaddress"].'</span>

					</div>
				</td>
			
				<td rowspan="2" width="100px" height="120.7px" style="border-bottom: 1px solid #000;">

						<div style="width: 100px; height: 120.7px; padding: 0; margin: 0;">
						</div>
				</td>
			</tr>
				
			<tr>
				<td  width="330px"; height="60.3px" style="border-right: 1px solid #000;border-bottom: 1px solid #000;">
					<div style="width: 14px; height: 60.3px;">
						<span>寄件</span>
					</div>
				</td>

				<td width="237.85px" height="60.3px" style="border-right: 1px solid #000;border-bottom: 1px solid #000;">
					<div style="width: 237.85px; height: 65px;line-height:15px;">
						<span style="font-family: \'宋体\';font-size: 10pt;">'.$v["sendman"].'</span><br>
						<span style="font-family: \'宋体\';font-size: 10pt;">电话：'.$v["sendmanphone"].'</span><br>
						<span style="font-family: \'宋体\';font-size: 10pt;">地址：'.$v["sendprovince"].$v["sendcity"].$v["sendcounty"].$v["sendmanaddress"].'</span>
					</div>
				</td>	
			</tr>
				
		</table>
		</td>
	</tr>
	<tr>
		<td colspan="2">
		<table width="330px" height="40px" style="margin-left: 10px;">

			<tr>
				<td style="text-align:right;">
					已检视('.$order_info['box_no'].')
				</td>
			</tr>
		</table>
		</td>
	</tr>
</table>';
		$text[$k]=$text_head.$text_body.$text_end;
	  }
	 
	  $return['status']=1;
	  $return['info']=$text;
	  // echo $text;
	  $this->ajaxReturn($return);
	}
	
	//批量打印百世英文面单--预览/直接打印
	public function ajax_printbatBSE(){
	  $id=I('id');
	  $preview=I('preview');
	  // $m=M('Pushorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
	  $n=M('Printorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
	  $g=M('Pushordergoods', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
	  $p=M('Pushorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
	  $printerid_list=$id;
	  $map['id']=array('in',$printerid_list);
	  $order_list=$p->field('order_no')->where($map)->select();//订单列表
	  
	  foreach($order_list as $keys=>$values){
		  $order_no_list[$keys]=$values['order_no'];
	  }
	  
	  $mapss['order_no']=array('in',$order_no_list);
	  $printorder_list=$n->where($mapss)->group('order_no')->select();
	  // echo $n->getlastsql();
	  if(empty($preview)){//非预览状态
		  $p->where($map)->save(array('printer_name'=>session('username'),'times'=>array('exp','times+1')));//更新打印次数
	  }
	  
	  // dump($printorder_list);
	  // die;
	  foreach($printorder_list as $k=>$v){
		  $order_info=$p->field('id')->where(array('order_no'=>$v['order_no']))->find();
		  $order_id=$order_info['id'];
		  $goods_info=$g->where(array('order_id'=>$order_id))->limit(20)->select();
		  // $printorder_list[$k]['goods_info']=$goods_info;
		  $count=count($goods_info);
		  foreach($goods_info as $ks=>$vs){
			 $goods_text='<p style="font-size: 12px;">'.msubstr($vs['goods_name'],0,12).'</p>
                        <p style="font-size: 12px;">数量:'.$vs['goods_nums'].'</p>';
		  }
		  $text_head='<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>百世面单</title>
<style type="text/css">
body,html{padding: 0; margin:0;color:#333;text-decoration: none;font-size: 9pt;font-family:Arial, Helvetica, sans-serif;}
p{margin:0; padding:0;}
.clear{clear:both;}
.ord_warp{width:365px; margin:0 auto; height:auto; height:auto; border:1px solid #333;}
.ord_top{height:45px; width:100%; padding:0px 10px;}
.ord_logo{padding-top:7px;float:left; width:50%;}
.ord_tr{float:left; width:50%;}
.ord_tf{font-size:14pt; font-weight:bold; padding-top:2px;}
.ord_te{font-family:Arial, Helvetica, sans-serif; font-size:9pt; color:#4A4A4A;}
.ord_title{border-top:1px solid #000; border-bottom:1px solid #333; padding:3px 0px;}
.ord_title p{font-size:17pt; font-weight:bold;text-align:center; font-family:"微软雅黑"}
.ord_te2{font-family:Arial, Helvetica, sans-serif; font-size:10pt; text-align:center; display:block; color:#4A4A4A;}
.ord_main{width:100%;}
.ord_ml{width:220px; float:left;}
.ord_mlm{width:100%; border-bottom:1px solid #333;}
.ord_mlt{width:49px; float:left; text-align:center; padding-top:35px;}
.ord_mlt2{width:50px; float:left; text-align:center;padding-top:22px;}
.ord_mlt_s{ font-weight:bold;font-family:"微软雅黑"}
.ord_te3{font-family:Arial, Helvetica, sans-serif; font-size:9pt;color:#4A4A4A; font-weight:bold; text-transform:capitalize;}
.ord_mlx{width:170px; padding:5px 0px; float:left; border-left:1px solid #333;font-weight:bold; height:85px;}
.ord_mlx p{padding:0px 5px; font-weight:bold; padding-bottom:4px; line-height:13px;}
.ord_mr{float:left; width:144px; border-left:1px solid #333; }
.order_s{width:100%; padding:5px 0px; text-align:center; border-bottom:1px solid #333;}
.order_sm{padding:5px; border-bottom:1px solid #333; height:138px;}
.ord_mlt_s2{ font-size:9pt; line-height:14px; padding-bottom:4px;font-family:"微软雅黑"}
.ord_te4{font-family:Arial, Helvetica, sans-serif; font-size:9pt;color:#4A4A4A;text-transform:capitalize;}
.ord_inp{border:0px; width: 25px;font-size: 9pt; font-weight:bold; outline:none; padding-left:2px; line-height:14px; width:67px;}
.ord_cod{width:100%; padding:8px 0px;}
.ord_cod img{ display:block; margin:0 auto;}
.ord_qian{width:100%; border-bottom:1px solid #333; border-top:1px solid #333; height:70px;}
.ord_ql{width:61%; float:left;}
.ord_ql p{font-family:Arial, Helvetica, sans-serif;font-size:9pt;color:#333; line-height:13px; padding:3px 5px 0px 5px;}
.ord_qm{width:38.7%; float:left; border-left:1px solid #333; height:70px;}
.ord_qm p{padding-left:5px; padding-top:12px;}
.ord_midd{padding:20px 10px 5px; border-bottom:1px solid #333;}
.ord_midd_l{padding-top:8px; float:left;}
.ord_midd_r{float:right;}
.ord_tb{width:100%;}
.ord_ml2{width:365px;}
.ord_mlx2{width:314px; padding:2px 0px; float:left; border-left:1px solid #333;font-weight:bold;height:64px;}
.ord_mlx2 p{padding:0px 5px; font-weight:bold; padding-bottom:4px; line-height:13px;}
.ord_footer{height:25px; width:100%;}
.ord_footer p{text-align:right; padding-right:5px; padding-top:8px;}
@media print {
	.break {page-break-after:always;}
}
</style>
<script type="text/javascript" src="./Public/Admin/lib/jquery/1.9.1/jquery.min.js"></script>
</head>

<body>';
			$text_end='<div class="break" style="page-break-before:always;width:100%;height:0px;clear:both;">&nbsp;</div></body>';
			$text_body='<div class="ord_warp">
  <div class="ord_top">
    <div class="ord_logo"></div>
    <div class="ord_tr">
      <p class="ord_tf">成就商业•精彩生活</p>
      <p class="ord_te">Make a good life in business</p>
    </div>
    <div class="clear"></div>
  </div>
  
  <div class="ord_title">
    <p>'.$v["destcode"].'</p><span class="ord_te2">'.$v["destcode"].'</span>
  </div>
  
  <div class="ord_main">
    <div class="ord_ml">
     <div class="ord_mlm">
      <div class="ord_mlt">
        <p class="ord_mlt_s">收件</p><p class="ord_te3">receive</p>
      </div>
      <div class="ord_mlx">
        <p>'.$v["receiveman"].'</p>
        <p>Tel:'.$v["receivemanphone"].'</p>
        <p>Add:'.$v["receiveprovince"].$v["receivecity"].$v["receivecounty"].$v["receivemanaddress"].'</p>
      </div>
      <div class="clear"></div>
     </div> 
     
     <div class="ord_mlm">
      <div class="ord_mlt">
        <p class="ord_mlt_s">寄件</p><p class="ord_te3">sent</p>
      </div>
      <div class="ord_mlx">
        <p>'.$v["sendman"].'</p>
        <p>Tel:'.$v["sendmanphone"].'</p>
        <p>Add:'.$v["sendprovince"].$v["sendcity"].$v["sendcounty"].$v["sendmanaddress"].'</p>
      </div>
      <div class="clear"></div>
     </div>
     
    </div>
    
    <div class="ord_mr">
      <div class="order_s">
        <p class="ord_mlt_s">服务</p>
        <p class="ord_te3">service</p>
      </div>
      <div class="order_sm">
        <p class="ord_mlt_s2">代付/交付<span class="ord_te4">(Pay/delivery)</span>:<input type="text" value="Pay" class="ord_inp"></p>
        <p class="ord_mlt_s2">保价金额<span class="ord_te4">(Insured amount)</span>:<input type="text" value="0yuan" class="ord_inp"></p>
        <p class="ord_mlt_s2">报价费用<span class="ord_te4">(Quote price)</span>:<input type="text" value="0yuan" class="ord_inp"></p>
        <p class="ord_mlt_s2">其他说明<span class="ord_te4">(other instructions)</span>:</p>
      </div>
      
    </div>
    
    <div class="clear"></div>
  </div>
  
  <div class="ord_cod"><img src="/Public/plugins/barcodegen/test_1D.php?text='.$v['mailno'].'" width="189" height="55" /></div>
  <div class="ord_qian">
    <div class="ord_ql"><p>Your receipt for this single, on behalf of your acceptance, to confirm the goods information is correct, packaging intact, no scratches, damage and other surface quality problems</p></div>
    <div class="ord_qm">
      <p><strong>收件人</strong><span class="ord_te3">(receiver):</span></p>
      <p><strong>时间</strong><span class="ord_te3">(time):</span></p>
    </div>
    <div class="clear"></div>
  </div>
  
  <div class="ord_midd">
    
    <img src="/Public/plugins/barcodegen/test_1D.php?text='.$v['mailno'].'" width="155" height="55" class="ord_midd_r"/>
    <div class="clear"></div>
   </div>
   
    <div class="ord_ml2">
     <div class="ord_mlm">
      <div class="ord_mlt2">
        <p class="ord_mlt_s">收件</p><p class="ord_te3">receive</p>
      </div>
      <div class="ord_mlx2">
        <p>'.$v["receiveman"].'</p>
        <p>Tel:'.$v["receivemanphone"].'</p>
        <p>Add:'.$v["receiveprovince"].$v["receivecity"].$v["receivecounty"].$v["receivemanaddress"].'</p>
      </div>
      <div class="clear"></div>
     </div> 
     
     <div class="ord_mlm">
      <div class="ord_mlt2">
        <p class="ord_mlt_s">寄件</p><p class="ord_te3">sent</p>
      </div>
      <div class="ord_mlx2">
        <p>'.$v["sendman"].'</p>
        <p>Tel:'.$v["sendmanphone"].'</p>
        <p>Add:'.$v["sendprovince"].$v["sendcity"].$v["sendcounty"].$v["sendmanaddress"].'</p>
      </div>
      <div class="clear"></div>
     </div>
     
    </div>
    
  <div class="ord_footer">
    <p class="ord_mlt_s">已检视<span class="ord_te3">(View planned cost)</span></p>
  </div>

   
</div>';
			$text[$k]=$text_head.$text_body.$text_end;
	  }
	 
	  $return['status']=1;
	  $return['info']=$text;
	  $this->ajaxReturn($return);
	}
	//批量打印中通面单--预览/直接打印
	public function ajax_printbatZTO(){
	  $id=I('id');
	  $preview=I('preview');
	  // $m=M('Pushorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
	  $n=M('Printorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
	  $g=M('Pushordergoods', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
	  $p=M('Pushorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
	  $printerid_list=$id;
	  $map['id']=array('in',$printerid_list);
	  $order_list=$p->field('order_no')->where($map)->select();//订单列表
	  foreach($order_list as $keys=>$values){
		  $order_no_list[$keys]=$values['order_no'];
	  }
	  
	  $mapss['order_no']=array('in',$order_no_list);
	  $printorder_list=$n->where($mapss)->group('order_no')->select();
	  // echo $n->getlastsql();
	  if(empty($preview)){//非预览状态
		  $p->where($map)->save(array('printer_name'=>session('username'),'times'=>array('exp','times+1')));//更新打印次数
	  }
	  
	  // dump($printorder_list);
	  // die;
	  foreach($printorder_list as $k=>$v){
		  $order_info=$p->field('id')->where(array('order_no'=>$v['order_no']))->find();
		  $order_id=$order_info['id'];
		  $goods_info=$g->where(array('order_id'=>$order_id))->limit(20)->select();
		  // $printorder_list[$k]['goods_info']=$goods_info;
		  $count=count($goods_info);
		  foreach($goods_info as $ks=>$vs){
			 $goods_text='<p style="font-size: 12px;">'.msubstr($vs['goods_name'],0,12).'</p>
                        <p style="font-size: 12px;">数量:'.$vs['goods_nums'].'</p>';
		  }
		  $text_head='<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>百世面单</title>
<style>
@media print {
	.break {page-break-after:always;}
}
body,html{padding: 0; margin:0;color:#333;text-decoration: none;font-size:8pt;font-family:"微软雅黑";-webkit-text-size-adjust:none;}
p{margin:0; padding:0;}
.clear{clear:both;}
.or_warp{width:378px;height:auto; margin:0 auto; border:2px solid #2a6082;}
.or_main{height:98%; width:96%; border:4px solid #0969b3; margin:1% auto;}
.or_top{height:40px; border-bottom:1px solid #000;}
.or_logo{width:110px; height:28px; float:left; padding:6px 0px 0px 10px;}
.or_tright{float:right; font-size:12pt; color:#fff; line-height:40px; padding:0px 10px; background-color:#000;}
.or_titlte{height:40px; text-align:center; line-height:40px; font-size:18pt; font-weight:bold; border-bottom:1px solid #000;}
.or_table{border-bottom:8px solid #000; height:auto;}
.or_fmain{border-bottom:1px solid #000; height:140px;}
.or_tatop{height:36px; line-height:36px;}
.or_tat_l{width:70%; float:left; text-align:center; font-size:13pt; font-weight:bold;}
.or_tat_r{width:29%; float:left; text-align:center; border-left:1px solid #000;}
.or_ml{width:70%; float:left;}
.or_ml_jian{width:100%; border-top:1px solid #000;height:70px;}
.or_ml_l{width:12px; float:left;padding:18px 10px 0px 10px;}
.or_ml_l2{width:15px; float:left;padding:25px 10px 0px 10px;} 
.or_ml_r{width:83%; float:left; border-left:1px solid #000;  padding:5px 5px 15px 5px;height:50px;}
.or_ml_rf{font-size:8pt; line-height:14px; margin-bottom:3px;}
.or_ml_rf2{font-size:8pt; font-weight:bold; line-height:14px; margin-top:1px;}
.or_mr{width:29.5%; float:left;border-left:1px solid #000;border-top:1px solid #000;height:140px;}
.or_mr_t{ border-bottom:1px solid #000; height:24px; line-height:24px; text-align:center;}
.or_mr_b{padding-left:2px;}
.or_mr_b p{line-height:14px;}
.or_tacode{
	padding:3px 0;
}
.or_tacode img{display:block; margin:2px auto;width:250px;height:62px;}
.or_tabo{border-top:1px solid #000; height:75px}
.or_taba_l{width:52%; float:left; font-size:8pt; line-height:14px; padding:2px 5px 0px 5px; height:75px;}
.or_taba_m{width:23%; float:left; border-left:1px solid #000; border-right:1px solid #000; height:75px;}
.or_taba_m p{font-size:9pt; font-weight:bold; line-height:16px; padding-left:5px; padding-top:15px;}
.or_taba_r{width:20%; float:left; font-weight:bold; text-align:center; line-height:20px; padding-top:5%;height:75px;}
.or_boto{padding:2px 10px; border-bottom:1px solid #000;}
.logo2{float:left; padding-top:10px;}
.code2{float:right;}
.or_ml2{width:100%;}
.or_bobo{height:30px; padding:1px 10px; border-top:1px solid #000;}
.or_bobo2{text-align:right; padding-top:0px;}
</style>
<script type="text/javascript" src="./Public/Admin/lib/jquery/1.9.1/jquery.min.js"></script>
</head>

<body>';
			$text_end='<div class="break" style="page-break-before:always;width:100%;height:0px;clear:both;">&nbsp;</div></body>';
			$text_body='<div class="or_warp">
  <div class="or_main">
    <div class="or_top">
      <div class="or_logo"></div>
      <div class="or_tright">标准快递&nbsp;</div>
      <div class="clear"></div>
    </div>
    <div class="or_titlte">'.$v["destcode"].'</div>
    <div class="or_table">
      <div class="or_tatop">
        <div class="or_tat_l">'.$v["billprovidesitename"].'</div>
        <div class="or_tat_r">'.date("Y-m-d",$v["add_time"]).'</div>
        <div class="clear"></div>
      </div>
      <div class="or_fmain">
        <div class="or_ml">
          <div class="or_ml_jian">
            <div class="or_ml_l">收件</div>
            <div class="or_ml_r">
              <p class="or_ml_rf">'.$v["receiveman"].'&nbsp;&nbsp;'.$v["receivemanphone"].'</p>
              <p class="or_ml_rf2">'.$v["receiveprovince"].$v["receivecity"].$v["receivecounty"].$v["receivemanaddress"].'</p>
            </div>
            <div class="clear"></div>
          </div>
          
          <div class="or_ml_jian">
            <div class="or_ml_l">寄件</div>
            <div class="or_ml_r" style="height:49px;">
              <p class="or_ml_rf">'.$v["sendman"].'&nbsp;&nbsp;'.$v["sendmanphone"].'</p>
              <p class="or_ml_rf">'.$v["sendprovince"].$v["sendcity"].$v["sendcounty"].$v["sendmanaddress"].'</p>
            </div>
            <div class="clear"></div>
          </div>
          
        </div>
        <div class="or_mr">

        </div>
        <div class="clear"></div>
      </div>
      <div class="or_tacode"><img src="/Public/plugins/barcodegen/test_1D.php?text='.$v['mailno'].'" alt="barcode"/></div>
      <div class="or_tabo">
        <div class="or_taba_l">
          快件送达收件人地址，经收件人或收件人（寄件人）允许的代收人签字，视为送达。您的签字代表您已验收此包裹，并已确认商品信息无误，包装完好，没有划痕、破损等表面质量问题。
        </div>
        <div class="or_taba_m">
          <p>签收人：</p>
          <p>时间：</p>
        </div>
        <div class="or_taba_r"></div>
        <div class="clear"></div>
      </div>
    <div>

    
  </div>
</div>

    <div class="or_boto">
	  <span style="width:130px;height:28px;float:left;">&nbsp;</span>
      <img width="195" height="50" src="/Public/plugins/barcodegen/test_1D.php?text='.$v['mailno'].'" alt="barcode"/>
      <div class="clear"></div>
    </div>
    
       <div class="or_ml2">
          <div class="or_ml_jian">
            <div class="or_ml_l2">收件</div>
            <div class="or_ml_r">
              <p class="or_ml_rf">'.$v["receiveman"].'&nbsp;&nbsp;'.$v["receivemanphone"].'</p>
              <p class="or_ml_rf">'.$v["receiveprovince"].$v["receivecity"].$v["receivecounty"].$v["receivemanaddress"].'</p>
            </div>
            <div class="clear"></div>
          </div>
          
          <div class="or_ml_jian">
            <div class="or_ml_l2">寄件</div>
            <div class="or_ml_r">
              <p class="or_ml_rf">'.$v["sendman"].'&nbsp;&nbsp;'.$v["sendmanphone"].'</p>
              <p class="or_ml_rf">'.$v["sendprovince"].$v["sendcity"].$v["sendcounty"].$v["sendmanaddress"].'</p>
            </div>
            <div class="clear"></div>
          </div>

        </div>
        
        <div class="or_bobo">
          <p>&nbsp;</p>
          <p class="or_bobo2">已验视</p>
        </div></div></div>';
		$text[$k]=$text_head.$text_body.$text_end;
	  }
	 
	  $return['status']=1;
	  $return['info']=$text;
	  // echo $text;
	  $this->ajaxReturn($return);
	}
	/**
	*出库申报
	**/
	public function pushoutboundstorage(){
		$id=I('id');
		$m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		$pushapi = A('Pushsendapi'); 
		$res=$pushapi->get_method();//出库申报
		
		if($res['flag']==1){
			$m->where(array('id'=>$id))->setField('is_delivery',1);
		}

		$this->ajaxReturn($res);
	}
	
	//拦截
	  Public function zintercepted(){
		  $Intercept=M('Intercept', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		  $InterceptOrder=M('InterceptOrder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		  $Printorder=M('Printorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		  $Pushordergoods=M('Pushordergoods', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		  $Pushorder=M('Pushorder', C('DB_PREFIX_T'), C('DB_TYPE') . '://' . C('DB_USER') . ':' . C('DB_PWD') . '@' . C('DB_HOST') . ':' . C('DB_PORT') . '/' . C('erp_dbname'));
		  
		  $inter_list=$Intercept->where(array('status'=>1))->select();//获取拦截列表
		  $InterceptOrder->where('1')->delete();//删除所有拦截订单数据
		  
		  foreach($inter_list as $k=>$v){
			  $tval=$v['val'];
			  $tkey=$v['key'];
			  if($v['key']=='receiveProvince' or $v['key']=='receiveCity' or $v['key']=='receiveCounty'){  //按地区筛选订单号
				  $map[$tkey]=array('like',"%$tval%");
				  $map['status']=array('neq',-1);
				  $list_orderno=$Printorder->field('order_no')->where($map)->select();
				  foreach($list_orderno as $k => $v){
				  	  $data['order_no']=$v['order_no'];
				  	  if($v['order_no']){
				  		  $state=$InterceptOrder->where('order_no="'.$v['order_no'].'"')->find();
				  		  if($state==NULL){	//如果没有重复订单数据
				  			  $status=$InterceptOrder->add($data);
				  			  if($status){
				  				  continue;
				  			  }else{
				  				 $this->error('出错');  
				  			  }
				  		  }
				  	  }
				   }
			  }else if($v['key']=='goods_name'){			//按商品名称筛选订单号
				  $map[$tkey]=array('like',"%$tval%");
				  $list_orderid=$Pushordergoods->field('order_id')->where($map)->select();
				  foreach($list_orderid as $k=>$v){
					  $list_orno=$Pushorder->field('order_no')->where('id='.$v['order_id'])->find();
					  $data['order_no']=$list_orno['order_no'];
					  if($list_orno['order_no']){
						  $state=$InterceptOrder->where('order_no="'.$v['order_no'].'"')->find();
						  if($state==NULL){
							  $status=$InterceptOrder->add($data);
							  if($status){
								  continue;
							  }else{
								 $this->error('出错');  
							  }
						  }
					   }
				  }
			  }else if($v['key']=='order_no'){						//直接筛选订单号
						  $data['order_no']=$v['val'];
						  if($v['val']){
						  $state=$InterceptOrder->where('order_no="'.$v['val'].'"')->find();
							  if($state==NULL){
								  $status=$InterceptOrder->add($data);
								  if($status){
									  continue;
								  }else{
									 $this->error('出错');
								  }
							  }
						  }
				}
		  }
		  
		  $list=$InterceptOrder->select();
		  return $list;
	  }
}